<template>
	<view class="bottomShare">
		<view class="shareTip" v-if="shareTip == true">
			<view class="mask" @click="showShareTip"></view>
			<image class="img" src="/static/public/images/share/tip.png"></image>
		</view>
		<view class="btn_box bg-white">
			<view class="u-flex">
				<view @click="copy" class="u-flex-1 sharebtn btn-copy">复制链接</view>
				<view v-if="isWeixn == true && isShowWxShare == true" @click="showShareTip" class="u-flex-1 sharebtn btn-wx">微信分享</view>
				<view @click="save" class="u-flex-1 sharebtn btn-save">保存图片</view>
			</view>
			<!-- <u-grid :col="isWeixn == true && isShowWxShare == true?3:2" class="u-grid" :border="false">
				<u-grid-item @click="copy" class="defaultbtn">
					<view class="btn">
						<image class="img" src="/static/public/images/share/icon_01.png"></image>
					</view>
					<view>复制链接</view>
				</u-grid-item>
				<u-grid-item v-if="isWeixn == true && isShowWxShare == true" @click="showShareTip">
					<view class="btn">
						<image class="img" src="/static/public/images/share/icon_02.png"></image>
					</view>
					<view>微信分享</view>
				</u-grid-item>
				<u-grid-item @click="save">
					<view class="btn">
						<image class="img" src="/static/public/images/share/icon_03.png"></image>
					</view>
					<view>保存图片</view>
				</u-grid-item>
			</u-grid> -->
		</view>
	</view>
</template>

<script>
	let isWeixn = false;
	//#ifdef H5
	var ua = navigator.userAgent.toLowerCase();
	if(ua.match(/MicroMessenger/i)=="micromessenger") {
		isWeixn =  true;
	} else {
		isWeixn = false;
	}
	//#endif
	export default {
		name: "bottomShare",
		props: {
			isShowWxShare: {
				type: Boolean,
				default: false
			},
			url: {
				type: String,
				default: '',
			},
			imgFile: {
				type: String,
				default: '',
			},
			goodsId: {
				type: Number,
				default: 0,
			}
		},
		data() {
			return {
				shareTip:false,
				isWeixn: isWeixn
			}
		},
		methods: {
			showShareTip(){
				this.shareTip = !this.shareTip;
			},
			copy(){
				let that = this;
				uni.setClipboardData({ data:that.url, success:function(data){
					that.$u.toast('复制成功.');
					if(that.goodsId > 0){
						that.shareGoods();
					}
				}, fail:function(err){
					that.$u.toast('复制失败，请重试.');
				}, complete:function(res){} })
			},
			save(){
				let that = this;
				if (this.imgFile == ''){
					return false;
				}
				/* #ifdef H5 */
				that.$u.toast('长按图片，保存图片.');
				return false;
				/* #endif */
				uni.saveImageToPhotosAlbum({ filePath: that.imgFile, success: function () {
					that.$u.toast('保存成功.');
					if(that.goodsId > 0){
						that.shareGoods();
					}
				}, fail:function(err){
					that.app.showModal('长按图片，保存图片.');
				}, complete:function(res){} })
			},
			shareGoods(){
				this.$u.post('shop/api.goods/shareGoods', {goods_id:this.goodsId,showLoading:false});
			}
		}
	}
</script>

<style lang="scss">
	.bottomShare{
		height: 220rpx;
		background: #fff;
		.shareTip {
			position: fixed;
			top: 0rpx;
			right: 0;
			width: 100%;
			text-align: right;
			height: 100%;
			z-index: 999;
			background: rgba(0, 0, 0, .5);
			.mask {
				position: absolute;
				z-index: 999;
				width: 100%;
				height: 100%;
			}
			.img {
				position: absolute;
				z-index: 1000;
				width: 750rpx;
				height: 600rpx;
				top: 0;
				right: 0;
			}
		}
		.btn_box {
			position: fixed;
			bottom: 30rpx;
			padding: 0 20rpx;
			width: 100%;
			.u-grid-item {
				background: none !important;
			}
			.btn {
				border-radius: 100%;
				width: 120rpx;
				height: 80rpx;
				background: #fff;
				text-align: center;
				margin-bottom: 20rpx;
				border:1rpx solid #cccccc;
				.img {
					padding-top: 28rpx;
					width: 56rpx;
					height: 56rpx;
				}
			}
		}
	}
	.sharebtn{
		height: 80rpx;
		line-height: 80rpx;
		text-align: center;
		color: #fff;
		
		&.btn-copy{
			background: #5CB61A;
			border-radius: 40rpx 0px 0px 40rpx;
		}
		&.btn-wx{
			background: #69bd2a;
		}
		&.btn-save{
			background: #87CC55;
			border-radius: 0px 40rpx 40rpx 0px;
		}
	}
</style>
